package jee.boot.module.sms.rest;

import jee.boot.common.basic.CrudController;
import jee.boot.common.basic.result.ResponseMessage;
import jee.boot.common.basic.result.Result;
import jee.boot.entity.sms.Sms;
import jee.boot.module.sms.SendSmsHelper;
import jee.boot.module.sms.service.SmsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 短信发送Controller
 *
 * @author zhilei.wang
 * @version 2018-01-25
 */
@RestController
@RequestMapping(value = "/sms")
public class SmsRestController extends CrudController<SmsService, Sms> {
    @Autowired
    private SendSmsHelper helper;

    /**
     * 发送短信
     *
     * @param entity
     * @return
     */
    @PostMapping("/send")
    public ResponseMessage<Sms> send(@RequestBody Sms entity) {
        if (entity.isAsyn()) {
            //异步短信,经过mq后排队发送
            helper.sendSmsAsyn(entity);
        } else {
            // 同步短信,直接发送
            helper.sendSmsSync(entity);
        }
        return Result.success(entity);
    }


}
